int getWidth() int getHeight()
So now rather than using hard-coded values for width and height, use the actual values of the panel.
Say that x
is the current value in the range 0.0
to 2*Math.PI
.
Then Math.sin( x )
is the function values in the range -1.0
to 1.0
.
The following code scales those values to fit the Java panel
The location (startXint, startYint)
is the left end of a small line segment that is part of the curve.
startX = x; startY = Math.sin( x ); int startXint = (int)( startX * (width-1)/(2*Math.PI) ); int startYint = (int)( -startY * (height-1)/2.0 + (height-1)/2.0 );
The right end of the line segment is computed by incrementing x by a small amount contained in inc
.
What does that look like?
endX = startX + ; endY = Math.sin( );